/*
 * JFTermApplet.java
 *
 * Created on August 11, 2007, 1:24 PM
 *
 * @author  pquiring
 */

import javaforce.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TermApplet extends javax.swing.JApplet implements KeyEventDispatcher {

  public boolean dispatchKeyEvent(KeyEvent e) {
    System.out.println("KeyEvent:" + e);
    if ((e.getSource() instanceof Buffer) && (e.getKeyCode() == e.VK_TAB)) {
      return true;  //do not pass on
    }
    return false;  //pass on as normal
  }

  /** Initializes the applet JFTermApplet */
  public void init() {
    try {
      java.awt.EventQueue.invokeAndWait(new Runnable() {
        public void run() {
          initComponents();
          KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(TermApplet.this);
          Settings.settings.loadSettings();
          setSize(Settings.settings.WindowXSize, Settings.settings.WindowYSize);
          setLocation(Settings.settings.WindowXPos, Settings.settings.WindowYPos);
//          if (Settings.settings.bWindowMax) setExtendedState(MAXIMIZED_BOTH);
          Menu.create(TermApplet.this, tabs, !JF.isWindows());
        }
      });
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    //disable TAB processing for Buffer
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);

    JF.loadCerts(getClass().getResourceAsStream("javaforce.crt")
      , getClass().getResourceAsStream("jfterm.crt"), "jfterm.sourceforge.net");
  }

  public void destroy() {
    System.exit(0);
  }

  /** This method is called from within the init() method to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    tabs = new javax.swing.JTabbedPane();

    addComponentListener(new java.awt.event.ComponentAdapter() {
      public void componentResized(java.awt.event.ComponentEvent evt) {
        formComponentResized(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(tabs, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(tabs, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE)
    );
  }// </editor-fold>//GEN-END:initComponents

  private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
    validate();
  }//GEN-LAST:event_formComponentResized


  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JTabbedPane tabs;
  // End of variables declaration//GEN-END:variables
}
